<template>
<div>
    <meta title="参数设置"></meta>
    <ManageTable border stripe :rowKey="tableData.rowKey" :columns="tableData.columns" :data="tableData.data" :btnGroup="tableData.btnGroup" :page="tableData.page">
    </ManageTable>
</div>
</template>

<script>
import then from "thenjs";
import moment from "moment";
import AppFrame from "../../../libs/app-frame";
import ManageTable from "../../../components/manage-table";
export default {
  components: {
    ManageTable
  },
  data: function() {
    return {
      tableData: {
        rowKey: "ConfigKey",
        columns: [
          {
            type: "selection",
            width: 60,
            align: "center"
          },

          {
            title: "变量名",
            key: "ConfigKey",
            width: 220,
            filterKey: "ConfigKey",
            filterType: "text"
          },
          {
            title: "变量值",
            key: "ConfigValue",

            ellipsis: true
          },
          {
            title: "描述",
            width: 220,
            key: "ConfigInfo"
          },

          {
            title: "操作",
            key: "action",
            width: 160,
            align: "center",
            render: (h, params) => {
              return h("div", [
                h(
                  "Button",
                  {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: () => {
                        this.$router.push(
                          "/Manage/System/Params/Edit?ConfigKey=" +
                            params.row.ConfigKey
                        );
                        //alert(JSON.stringify(params))
                      }
                    }
                  },
                  "编辑"
                )
              ]);
            }
          }
        ],
        data: [],
        btnGroup: [
          {
            text: "删除所选",
            type: "primary",
            url: "/manage-api/system/params/Del",
            isShow: true,
            icon: "trash-a",
            loading: false,
            actionText: "确定要删除所选吗?"
          }
        ],
        page: {
          total: 0,
          current: 1,
          pageSize: 20
        }
      },
      QueryModel: {
        Sort: null
      }
    };
  },
  created: function() {
    this.setDefaultData();
    this.find();
  },
  watch: {
    $route: function() {
      //当路由改变时
      this.setDefaultData();
      this.find();
    }
  },
  methods: {
    setDefaultData: function() {
      this.tableData.page.current = Number(this.$route.query.CurPage) || 1;
      this.tableData.page.pageSize = Number(this.$route.query.PageSize) || 20;
    },
    find: function() {
      let self = this;
      let PostData = {};
      if (this.$route.query) PostData = this.$route.query;
      PostData.CurPage = this.tableData.page.current;
      PostData.PageSize = this.tableData.page.pageSize;
      then(function(defer) {
        AppFrame.Http.Post("/manage-api/system/params/getItems", PostData, defer);
      })
        .then(function(defer, Ret) {
          if (Ret && Ret.Result == 1) {
            console.log(Ret);
            self.tableData.page.total = Ret.Data.RsCount;
            self.tableData.page.current = Ret.Data.CurPage;
            self.tableData.page.pageSize = Ret.Data.PageSize;
            self.tableData.data.splice(0, self.tableData.data.length);
            Ret.Data.DataList.forEach(function(item) {
              item.UserCreatetime = moment
                .unix(item.UserCreatetime)
                .format("YYYY-MM-DD hh:mm:ss");
              self.tableData.data.push(item);
            });
          } else {
            defer({
              msg: Ret.Msg
            });
          }
        })
        .fin(function(defer, err, ret) {
          console.log(err);
          self.$Message.error("操作错误,请重试");
        });
    }
  }
};
</script>

<style scoped>
</style>